﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using AG.MapEditor.Data;
using System.IO;

namespace AGMapEditor
{
    static class Program
    {
        public const string APPCODE = "MAP-EDITOR";

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\data\\data.xml"))
            {
                MessageBox.Show("未发现资源文件!");
                return;
            }
            AGMEContext.InitData(AppDomain.CurrentDomain.BaseDirectory + "\\data\\data.xml");

            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\data\\unit.xml"))
            {
                AGMEContext.Current.DataLoader.LoadUnitList(AGMEContext.Current.Data,
                    AppDomain.CurrentDomain.BaseDirectory + "\\data\\unit.xml");
            }
            else
            {
                if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\metadata\\unit-category.xml"))
                {
                    AGMEContext.Current.DataLoader.LoadUnitCategoryList(AGMEContext.Current.Data,
                        AppDomain.CurrentDomain.BaseDirectory + "\\metadata\\unit-category.xml");
                }
            }

            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\metadata\\model-category.xml"))
            {
                AGMEContext.Current.DataLoader.LoadModelCategoryList(AGMEContext.Current.Data,
                    AppDomain.CurrentDomain.BaseDirectory + "\\metadata\\model-category.xml");
            }

            AGMEContext.Current.DataLoader.LoadObjectCategoryList(AGMEContext.Current.Data,
                AppDomain.CurrentDomain.BaseDirectory + "\\metadata\\object-category.xml");

            Application.Run(new MainWindow());
        }
    }
}
